<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['ischecklogin']=model('core/core')->checklogin('','',true);
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['orderid']);
	if($orderid){
		$order=pdo_get('jy_weishop_order',array('uniacid'=>$uniacid,'id'=>$orderid));
	}else{
		exi('订单ID不存在！','error','/index/');   
	}
	$dianinfo=$this->get('agent',array('uniacid'=>$uniacid,'mid'=>$_SESSION['uid']));
	if(!$dianinfo['id']){
		exi('您还不是自提点管理员，不能核销！！','error'); 
	}
	$dian_order=pdo_get('jy_area_dian_order',array('uniacid'=>$uniacid,'orderid'=>$order['id']));
	$dianinfo=$this->get('agent',array('uniacid'=>$uniacid,'id'=>$dian_order['dian_id']));
	if($dian_order['dian_id']!=$dianinfo['id']){
		exi('该订单不属于你的网点，不能核销！！','error'); 
	}
	if($order['status']==4){
		exi('订单已关闭，不能核销！','error','jy_area_dian/index/');
	}elseif($order['status']==5){
		exi('订单已申请退款，不能核销！','error','jy_area_dian/index/');
	}elseif($order['status']==5){
		exi('订单已退款，不能核销！','error','jy_area_dian/index/');
	}
	$address=$order['address']?json_decode($order['address'],true):$order['addressid'];
	if($address){
		$order['realname']=$address['name']?:$order['realname'];
		$order['addressinfo']=model('core/member')->get_address_str($address);
	}
	$order['address']=$address;
	$order_goods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$uniacid,'orderid'=>$order['id']));
	foreach($order_goods as &$item){
		$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid']),array('title','image'));
		//商品规格
		if($item['optionid']){
				$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$item['optionid']),'specs');
				$specs=explode("_",$specs);
				foreach($specs as &$spec){
					$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
				}
				$goods['selespename']=implode("，",$specs);
		}
		$item=array_merge($goods,$item);
	}
	$return['post']=array(
		'orderid'=>$order['id'],
	);
	if($order['sendtype']!=2){
		$order['statustitle']=$this->order_status[$order['status']];
	}else{
		$order['statustitle']=$this->order_status[$order['status']];
	}
	$order['createtime']=date('Y-m-d H:i:s',$order['createtime']);
	$selfinfo=pdo_get('jy_weishop_order_self',array('orderid'=>$order['id']));
	$selfinfo['selftime']=$selfinfo['selftime']?date('Y-m-d H:i:s',$selfinfo['selftime']):'尽快';
	$selfinfo['selftime']=$selfinfo['out_time']?:$selfinfo['selftime'];
	$selfinfo['number2']=substr($selfinfo['number'],-4);
	$order['selfinfo']=$selfinfo;
	$order['address']['name']=$order['address']['name']?:$selfinfo['username'];
	$order['address']['mobile']=$order['address']['mobile']?:$selfinfo['mobile'];
	$order['address']['name']=$order['address']['name']?:$order['realname'];
	$order['address']['mobile']=$order['address']['mobile']?:$order['mobile'];
	$return['order']=$order;
	$return['order_goods']=$order_goods;
	set_html('title','自提核销');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$orderid=intval($post['orderid']);
	$this->model('model')->order_verify($orderid);
	exi('自提核销成功！','','jy_area_dian/index/');
	
}